<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title>Flight</title>
    <script>
        var passengers = [
            {name: "Jane Doloop", paid: true, ticket: "coach"},
            {name: "Dr. Evel", paid: true, ticket: "firstclass"},
            {name: "Sue Property", paid: false, ticket: "firstclass"},
            {name: "John Funcall", paid: true, ticket: "premium"},
        ];

        function processPassengers(passengers, testFunction) {
            for (var i = 0; i < passengers.length; i++) {
                var passenger = passengers[i];
                if (testFunction(passenger)) {
                    return false;
                }
            }
            return true;
        }

        function checkNoFlyList(passenger) {
            return (passenger.name === "Dr. Evel");
        }
        function checkNotPaid(passenger) {
            return !passenger.paid;
        }

        var allCanFly = processPassengers(passengers, checkNoFlyList);
        if (!allCanFly) {
            console.log("The plane can't take off: we have a passenger on the no-fly-list.");
        }

        var allPaid = processPassengers(passengers, checkNotPaid);
        if (!allPaid) {
            console.log("The plane can't take off: not everyone has.");
        }

        function servePassengers(passengers) {
            for (var i = 0; i < passengers.length; i++) {
                serveCustomer(passengers[i]);
            }
        }
        function serveCustomer(passenger) {
            var getDrinkOrderFunction = createDrinkOrder(passenger);
            var getDinnerOrderFunction = createDinnerOrder(passenger);

            // 让乘客点饮料
            getDrinkOrderFunction();

            // 让乘客点餐
            getDinnerOrderFunction();

            // 让乘客点饮料
            getDrinkOrderFunction();
            getDrinkOrderFunction();
        }
        function createDrinkOrder(passenger) {
            var orderFunction;

            if (passenger.ticket === "firstclass") {
                orderFunction = function() {
                    console.log("Would you like a cocktail or wine?");
                };
            } else if (passenger.ticket === "premium") {
                orderFunction = function() {
                    console.log("Would you like wine, cola or water?");
                };
            } else {
                orderFunction = function() {
                    console.log("Your choick is cola or water.");
                };
            }

            return orderFunction;
        }
        function createDinnerOrder(passenger) {
            var orderFunction;

            if (passenger.ticket === "firstclass") {
                orderFunction = function() {
                    console.log("Would you like a chicken or pasta?");
                };
            } else if (passenger.ticket === "premium") {
                orderFunction = function() {
                    console.log("Would you like a snack box or cheese plate?");
                };
            } else {
                orderFunction = function() {
                    console.log("Would you like peanuts or pretzels?");
                };
            }

            return orderFunction;
        }

        servePassengers(passengers);
    </script>
</head>
<body>
    
</body>
</html>